from variable import *
import xlwings as xw

def copy_0943():
    #       3.1.2 copy 0943表格到术前文件夹，编辑后转pdf
    os.chdir(MailWork_path)
    key = "FRM0943"
    if os.path.exists(Report_BasicPath):
        print(Report_BasicPath + " exitst")
        for root, dirs, files in os.walk(Report_BasicPath):
            if root == Report_BasicPath:  # 限定在Report_BasicPath下遍历文件
                for file in files:
                    if key in file:
                        print('找到包含"' + key + '"字符的文件,绝对路径为----->' + Report_BasicPath + '/' + file)
                        print('复制到----->' + MailWork_path + "/" + file)
                        src_file = os.path.join(root, file)
                        shutil.copy(src_file, MailWork_path)

    if not os.path.isfile(File_0943_Name):
        os.rename(src_file, File_0943_Name)

    if os.path.exists(MailWork_path + "/" + "FRM0943.xltm"):
        os.remove(MailWork_path + "/" + "FRM0943.xltm")
        print('移除后术前目录下有文件：%s' % os.listdir(MailWork_path))
    pass

    wb = xw.Book(MailWork_path + '\\' + File_0943_Name)
    sht_General = wb.sheets['General']
    sht_BaseSystem = wb.sheets['Base System']
    sht_FinalActivities = wb.sheets['Final Activities']

    Cell_General = ['G13', 'G15', 'G16', 'G17', 'G18']
    Value_General = [Hospital, PIUSerialNumber, SystermSerialNumber, DateService_0943, "NA"]
    for i in range(0,len(Cell_General)):
        sht_General.range(Cell_General[i]).value = Value_General[i]

    Cell_BaseSystem = ['G13', 'J13', 'G20', 'J22', 'J23', 'J24',
                       'G25', 'J27', 'J28', 'J29', 'G30', 'J32',
                       'J33', 'J34', 'G55', 'G56']
    Value_BaseSystem = [CubeVol_0943, CubeDiag_0943, SIDMinHeight_0943, SIDMinHeight_0, SIDMinHeight_30, SIDMinHeight_45,
                        SIDAverHeight_0943, SIDAverHeight_0, SIDAverHeight_30, SIDAverHeight_45, SIDMaxHeight_0943,
                        SIDMaxHeight_0, SIDMaxHeight_30, SIDMaxHeight_45, DC_High, DC_Low]
    for i in range(0, len(Cell_BaseSystem)):
        sht_BaseSystem.range(Cell_BaseSystem[i]).value = Value_BaseSystem[i]

    sht_FinalActivities.range('L26').value = DateService_0943
    wb.save(MailWork_path + '\\' + "FRM0943" + "_" + Hospital + "_" + PIUSerialNumber \
                 + "_" + Time_ATP_1 + "_" + "术前" + ".xlsx")

    

